const express = require('express')
const router = express.Router()
const {db} = require('../db/dbutils')

router.get('/test',(req,res)=>{
    db.all('select * from message',[],(err,rows)=>{
        res.send(rows)
    })
})
router.get('/list',(req,res)=>{
    db.all('select * from message',[],(err,rows)=>{
        res.send(rows)
    })
})
router.post('/add', (req,res)=>{
    let message = req.body
    console.log(message);
    let time2num = new Date().getTime()
    // res.send(typeof time2num)

    db.run("insert into message ('id','title','content','create_time') values(?,?,?,?)",[time2num,message.title,message.content,time2num],(err,rows)=>{
        if (err) {
            res.send(err)
        } else {
            res.send('添加数据成功')
        }
    })
    
})

module.exports = router